<?
define('INPAGE', true);

require_once 'core/include/init.php';
     
     $video_num = 5;
     $vide_range = "day";
     
     $tmp_num = intval(trim(strip_tags($_GET['num'])));
     if ($tmp_num > 0 and $tmp_num < 10)
     {
         $video_num = $tmp_num;
     }

     $arr_range = array();
     $arr_range[] = 'week';
     $arr_range[] = 'month';
     $arr_range[] = 'all';
     $arr_range[] = 'featured';      
                    
     $tmp_range = strtolower(addslashes((trim(strip_tags($_GET['v_range'])))));
     if (in_array($tmp_range,$arr_range))
     {
         $vide_range = $tmp_range;
     }
     
     $tmp_det = strtolower(addslashes((trim(strip_tags($_GET['v_det'])))));
     if ($tmp_det == "yes")
     {
         $v_det = true;
     }     
     else
     {
         $v_det = false;
     }
     
     if ($video_range = 'featured')
     {
         $v_url = 'http://www.youtube.com/api2_rest?method=youtube.videos.list_featured&dev_id=u2WGzE_7C_A';
     }
     else
     {
         $v_url = 'http://www.youtube.com/api2_rest?method=youtube.videos.list_popular&dev_id=u2WGzE_7C_A&time_range='.$vide_range;         
     }
     
     $arr_v = xml_to_array($v_url);     
     
     $popular_v_html = "";
     for ($j = 1; $j <= $video_num; $j++)
     {
         if (strlen($arr_v[$j]['TITLE']) > 100)
         {
             $arr_v[$j]['TITLE'] = substr($arr_v[$j]['TITLE'],0,60)."...";
         }
         if ($v_det)
         {
             
         }
         $popular_v_html .= '<div id=""><a href="http://www.youtube.com/watch?v='.$arr_v[$j]['ID'].'" target="_blank" title="Watch thsi video - '.$arr_v[$j]['TITLE'].'">'.$arr_v[$j]['TITLE'].'</a><br>';
         if ($v_det)
         {
             
         } 
         $popular_v_html .= "</div>";        
     }
     echo  $popular_v_html;  

 